<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Technician extends Base_Controller
{
    private static $data = array();
    //该控制器需要用到的模型数组
    protected $models=['technician_model','banner_model','app_common_model','comment_model','type_model','collect_model',
                    'project_technician_model','project_model','userhandle_model','orderlist_model','gift_model'];  
    public function __construct()
    {
        parent::__construct(); 
    }
        
    /**
     *@title 技师列表
     *@desc 技师列表接口
     *@input {"name":"companyId","type":"int","desc":"技师所属店铺Id"}
     *
     *
     *@output {"name":"code","type":"int","desc":"200:获取成功,400获取失败,无数据"}
     *@output {"name":"msg","type":"string","desc":"获取成功/获取失败"}
     *
     *@output {"name":"data","type":"array","desc":"技师数组","child":"1"} 
     *@output {"name":"data[index].technician.technicianId","type":"string","desc":"技师ID","child":"2"}
     *@output {"name":"data[index].technician.realName","type":"string","desc":"技师姓名","child":"2"} 
     *@output {"name":"data[index].technician.sevriceNo","type":"string","desc":"技师编号","child":"2"} 
     *@output {"name":"data[index].technician.giftNum","type":"string","desc":"礼物数量","child":"2"} 
     *@output {"name":"data[index].technician.jobName","type":"string","desc":"职业名称,如足疗师","child":"2"}
     *@output {"name":"data[index].technician.judge","type":"string","desc":"评价分值","child":"2"}
     *@output {"name":"data[index].technician.poster","type":"string","desc":"技师封面图片","child":"2"}
     *@output {"name":"data[index].technician.skill","type":"array","desc":"技师的技能数组","child":"2"}
     *@output {"name":"data[index].technician.tags","type":"string","desc":"技师职称,如高级技师","child":"2"}
     *@output {"name":"data[index].technician.workStatus","type":"string","desc":"技师当前状态1:上钟,0空闲","child":"2"}
     * */
    public function technicianList()
    {       
        $companyId=$this->input->post('companyId');         //技师所属行业ID        
        
        if(!$companyId){
            show301('店铺Id不能为空');
        }        
        
        $technician=$this->technician_model->getTechnician($companyId);
        if(!$technician){
            show400();
        }        
        show200($technician);              
    }
    
    
    /**
     *@title 技师详情页
     *@desc 技师详情页
     *@input {"name":"technicianId","require":"true","type":"string","desc":"技师Id"}
     *@input {"name":"userId","type":"int","desc":"用户ID,如果用户已登录则传此参数,用来判断用户是否已收藏等"}
     *
     *@output {"name":"code","type":"int","desc":"200:获取成功,400获取失败,无数据,300:各种提示信息"}
     *@output {"name":"msg","type":"string","desc":"获取成功/获取失败"}
     *
     *@output {"name":"data","type":"array","desc":"技师数组,下面是详细说明,index代表该数组下标"}
     *         
     *@output {"name":"data.detail","type":"array","desc":"技师数组","child":"1"} 
     *@output {"name":"data.detail.technicianId","type":"string","desc":"技师ID","child":"2"}
     *@output {"name":"data.detail.realName","type":"string","desc":"技师姓名","child":"2"} 
     *@output {"name":"data.detail.sevriceNo","type":"string","desc":"技师编号","child":"2"} 
     *@output {"name":"data.detail.giftNum","type":"string","desc":"礼物数量","child":"2"} 
     *@output {"name":"data.detail.zanNum","type":"string","desc":"点赞数量","child":"2"} 
     *@output {"name":"data.detail.collectNum","type":"string","desc":"收藏数量","child":"2"} 
     *@output {"name":"data.detail.jobName","type":"string","desc":"职业名称,如足疗师","child":"2"}
     *@output {"name":"data.detail.judge","type":"string","desc":"评价分值","child":"2"}
     *@output {"name":"data.detail.poster","type":"string","desc":"技师封面图片","child":"2"}
     *@output {"name":"data.detail.skill","type":"array","desc":"技师的技能数组","child":"2"}
     *@output {"name":"data.detail.tags","type":"string","desc":"技师职称,如高级技师","child":"2"}
     *@output {"name":"data.detail.signature","type":"string","desc":"技师个性签名","child":"2"}
     *@output {"name":"data.detail.is_collect","type":"boolean","desc":"是否收藏,是:true,否:flase","child":"2"} 
     *@output {"name":"data.detail.commentNum","type":"int","desc":"总评论条数","child":"2"} 
     *@output {"name":"data.detail.comment","type":"array","desc":"对技师的评论信息","child":"2"} 
     *@output {"name":"data.detail.comment.commentId","desc":"评价ID","child":"3"}
     *@output {"name":"data.detail.comment.userId","desc":"用户ID","child":"3"}
     *@output {"name":"data.detail.comment.nickName","desc":"用户昵称","child":"3"}
     *@output {"name":"data.detail.comment.realName","desc":"用户真实姓名","child":"3"}
     *@output {"name":"data.detail.comment.avatar","desc":"用户头像链接","child":"3"}
     *@output {"name":"data.detail.comment.content","desc":"评价内容","child":"3"}
     *@output {"name":"data.detail.comment.judge","desc":"评价分值","child":"3"}
     *@output {"name":"data.detail.comment.images","type":"array","desc":"评价的图片连接数组","child":"3"}
     *@output {"name":"data.detail.comment.createTime","type":"array","desc":"评价的时间","child":"3"}
     *@output {"name":"data.detail.giftTodayNum","type":"int","desc":"当日获取的礼物数量","child":"2"} 
     *@output {"name":"data.detail.gift","type":"array","desc":"技师当日得到的礼物数组","child":"2"} 
     *@output {"name":"data.detail.gift[index].giftId","type":"string","desc":"礼物ID","child":"3"}
     *@output {"name":"data.detail.gift[index].name","type":"string","desc":"礼物名称","child":"3"}
     *@output {"name":"data.detail.gift[index].url","type":"string","desc":"礼物图片链接","child":"3"}
     *@output {"name":"data.detail.gift[index].price","type":"string","desc":"礼物价格","child":"3"} 
     *@output {"name":"data.detail.gift[index].num","type":"string","desc":"礼物数量","child":"3"} 
     *@output {"name":"data.detail.gift[index].totalPrice","type":"string","desc":"礼物总价","child":"3"}
     *@output {"name":"data.detail.gift[index].createTime","type":"string","desc":"送礼物的时间","child":"3"} 
     *@output {"name":"data.detail.gift[index].userId","type":"string","desc":"送礼物的用户ID","child":"3"} 
     *@output {"name":"data.detail.gift[index].nickName","type":"string","desc":"送礼物的用户昵称","child":"3"} 
     *@output {"name":"data.detail.gift[index].realName","type":"string","desc":"送礼物的用户姓名","child":"3"} 
     *@output {"name":"data.detail.gift[index].avatar","type":"string","desc":"送礼物的用户头像链接","child":"3"} 
     *     
     *     
     *@output {"name":"data.project","type":"array","desc":"技师提供的服务项目数组","child":"1"} 
     *@output {"name":"data.project[index].projectId","type":"string","desc":"项目ID","child":"2"}
     *@output {"name":"data.project[index].title","type":"string","desc":"项目名称","child":"2"}
     *@output {"name":"data.project[index].poster","type":"string","desc":"项目封面","child":"2"}
     *@output {"name":"data.project[index].price","type":"string","desc":"项目价格","child":"2"}
     *@output {"name":"data.project[index].judge","type":"string","desc":"项目评价分值","child":"2"}
     *@output {"name":"data.project[index].sales","type":"string","desc":"项目销售数量","child":"2"}
     * */
    public function detail()
    {
        $technicianId=$this->input->post('technicianId');
        if (!$technicianId){
            show301('技师ID不正确');
        }
        $userId=$this->input->post('userId'); 
        $technician = $this->technician_model->getDetail($technicianId);      //获取技师详情
        if (!$technician){
            show400();
        }        
        $is_collect=$this->app_common_model->is_collect($userId,$technicianId,6);
        $is_zan=$this->app_common_model->is_zan($userId,$technicianId,0);        
        $technician['is_collect']=$is_collect;
        $technician['is_zan']=$is_zan;
        $where=['listId'=>$technicianId,'typeFlag'=>2];
        $dbArray['page']=['offset'=>0,'limit'=>1];
        $dbArray['order']=['createTime'=>'desc'];
        //获取评论信息
        $comments=$this->comment_model->getComments($where,$dbArray);
        if($comments){      
            $technician['comment']=$comments[0];
        }else{
            $technician['comment']=[];
        }
        $technician['collectNum']=$this->collect_model->getWhere_num(['typeFlag'=>6,'listId'=>$technicianId]);         //收藏数量
        //获取技师当天得到的礼物数据
        $gift=$this->orderlist_model->getGiftListToday($technicianId);
        $technician['gift']=$gift;
        $technician['giftTodayNum']=count($gift);       //当日 礼物数量
        
        $project=$this->project_technician_model->getList(['technicianId'=>$technicianId]);
        $data=[
            'detail'=>$technician,
            'project'=>$project       //暂时未做
        ];
        show200($data);
    }
    
    /**
     *@title 为技师点赞
     *@desc 为技师点赞
     *@input {"name":"technicianId","require":"true","type":"string","desc":"技师Id"}
     *@input {"name":"userId","type":"int","require":"true","desc":"当前登录用户ID"}
     *
     *@output {"name":"code","type":"int","desc":"200:点赞成功,400:点赞失败"}
     *@output {"name":"msg","type":"string","desc":"点赞成功/点赞失败"}
     * */
    public function clickZan()
    {
        $userId = $this->input->post('userId');
        $technicianId = $this->input->post('technicianId');
        if (!$userId){
            show3();
        }
        if(!$technicianId){
            show301('技师ID错误');
        }
        $data = array(
            'userId' =>$userId,
            'listId' => $technicianId,
            'typeFlag' => 0,        //点赞
            'flag' => 0         //资讯
        );
        $zan=$this->userhandle_model->getWhereRow($data);
        if($zan){
            show300('您已点过赞了');
        }
        
        $bool = $this->userhandle_model->insert_time($data);
        if ($bool){
            $this->technician_model->updateNumPlus(['technicianId'=>$technicianId],'zanNum');
            show200([],'点赞成功');
        }else{
            show400('点赞失败');
        }
    }
    
    /**
     *@title 礼物列表
     *@desc 礼物列表接口
     *
     *@output {"name":"code","type":"int","desc":"200:获取成功,400获取失败,无数据"}
     *@output {"name":"msg","type":"string","desc":"获取成功/获取失败"}
     *
     *@output {"name":"data","type":"array","desc":"技师数组","child":"1"}
     *@output {"name":"data[index].giftId","type":"string","desc":"礼物ID","child":"2"}
     *@output {"name":"data[index].name","type":"string","desc":"礼物名称","child":"2"}
     *@output {"name":"data[index].url","type":"string","desc":"礼物图片链接","child":"2"}
     *@output {"name":"data[index].price","type":"string","desc":"礼物价格","child":"2"}
     * */
    public function giftList()
    {       
        $select='giftId,name,concat("'.IMAGEHOST.'", url) as url,price';
        $gift=$this->gift_model->getWhere(['is_delete'=>0],$select);
        if(!$gift){
            show400();
        }
        show200($gift);
    }
    
    
    
    
    
    
}
